var orderId = "";
var memberId;
var teacherId;

$(".reply-content").css("height",(window.innerHeight-280)+"px");

function reply(){
  if(server.isEmpty(orderId)){
      pop_up("获取订单ID失败，请联系管理员");
      return;
  }
  server.loadindex('page/quickask/reask/reask','orderId='+orderId+'&memberId='+memberId+'&teacherId='+teacherId);
};
function finishorder(){
    if(server.isEmpty(orderId)){
        pop_up("获取订单ID失败，请联系管理员");
        return;
    }
    server.req('wechat/order/finishorder',{orderId:orderId},function (res) {
        console.log(res);
        if(res.code==0){
            // console.log("size....."+res.data.size())
            if(res.data==null){
                pop_up("你还没测试记录，不能结束");
                // server.loadindex('page/teacher/teacherindex/teacherindex');
                return;
            }

            pop_up("成功结束订单，期待您评价吧");
            server.loadindex('page/order/orderlist/orderlist');
        }
    })
}
$(function () {
    orderId = server.getQueryString("orderId");
    if(server.isEmpty(orderId)){
        pop_up("获取订单ID失败，请联系管理员");
        return;
    }
    server.req('wechat/order/infodto/'+orderId,{},function (res) {
        // console.log(res)
        if(res.code==0){
            if(res.data.status!=1){
                $("#btns").css('display','none');
            }
            memberId = res.data.memberId;
            teacherId = res.data.teacherId;
            server.loadData(".order",res.data);
            var goods = res.data.goods;
            var goodsName;
            if(goods){
                goods.forEach(function (item,index) {
                    if(server.isEmpty(goodsName)){
                        goodsName=item.itemName;
                    }else{
                        goodsName=goodsName+","+item.itemName;
                    }
                })
                $("#goodcontent").text(goodsName);
            }
            server.req('wechat/orderawnser/list',{orderId:orderId},function (e) {
                console.log('--------order awners--------')
                console.log(e)
                var answerHtml="";
                if(e.code==0){
                    if(e.data!=null&&e.data.length>0){
                        $("#nodata").css("display","none");

                        $("#awnserCount").text("(共有"+e.data.length+"条记录)");

                        e.data.forEach(function (answer,answerIndex) {
                            if(answer.awnserSide==1){
                                answerHtml = answerHtml + '<div class="reply-content-item">\n' +
                                    '                    <div class="reply-content-item-title">\n' +
                                    '                        <img src="'+answer.memberHeadimgurl+'" /><label>'+answer.memberNickname+'</label><label data-item="startDate" class="ctime">('+answer.startDate+')</label>' +
                                    '                    </div>\n' +
                                    '                    <div class="reply-content-item-content">\n' +
                                    '                        <label>'+answer.content+'</label>\n' +
                                    '                    </div>\n' +
                                    '                </div>';
                            }else{
                                answerHtml = answerHtml + '<div class="reply-content-item">\n' +
                                    '                    <div class="reply-content-item-title">\n' +
                                    '                        <img src="'+answer.teacherHeadimgurl+'" /><label>'+answer.teacherName+'</label><label data-item="startDate" class="ctime">('+answer.startDate+')</label>' +
                                    '                    </div>\n' +
                                    '                    <div class="reply-content-item-content">\n' +
                                    '                        <label>'+answer.content+'</label>\n' +
                                    '                    </div>\n' +
                                    '                </div>';
                            }

                        });
                        $("#answers").html(answerHtml);


                    }
                    // server.loadData(".reply-content",e);
                }
            })
        }
    })
})

